Why isn't garbage collection being activated in my code? [migrated]
Posted
by
Netmoon
on Programmers
See other posts from Programmers
or by Netmoon
Published on 2011-11-20T10:52:23Z
Indexed on
2011/11/20
18:25 UTC
Read the original article
Hit count: 246
I have a foreach
statement in my code, where each iteration calculates huge amounts of data and goes to the next iteration. I run this code, but when I read the log, I see there's a memory leak error.
PHP.net says when this happens, using gc_enabled()
is a good way to handle this.
I've added these lines to last line of the foreach
block:
echo "Check GC enabled : " . gc_enabled();
echo "Number of affected cycles : " . gc_collect_cycles();
And this is the output:
Check GC enabled : 1
Number of affected cycles : 0
Why do cycles exist, but the affected cycles is 0?
© Programmers or respective owner